package CandyCraft.common;

import java.awt.Color;
import java.io.File;
import java.util.logging.Logger;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.Minecraft;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EnumCreatureType;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.src.ModLoader;
import net.minecraft.world.biome.BiomeGenBase;
import net.minecraftforge.common.Configuration;
import net.minecraftforge.common.ForgeVersion;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.Property;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.Init;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.Mod.PostInit;
import cpw.mods.fml.common.Mod.PreInit;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.network.NetworkMod;
import cpw.mods.fml.common.registry.EntityRegistry;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry;

@Mod(modid = "Candy_Craft", name = "Candy Craft", version = "0.0.1")
@NetworkMod(clientSideRequired = true, serverSideRequired = false)

public class mod_CandyCraft {
	

	public static Logger log;
	private Minecraft mc;
	public static int paperBlockId = 175;
	public static int chocolateGrassId = 176;
	public static int chocolateDirtId= 177;
	public static int cottonCandyLeavesId= 178;
	public static int cottonCandySaplingId= 179;
	public static int taffyLogId= 180;
	BiomeGenRapists_Paradise biome = new BiomeGenRapists_Paradise(50);

	

	@Instance("tutorial")
	public static mod_CandyCraft instance;
	
	@SidedProxy(clientSide = "CandyCraft.common.CommonProxy", serverSide = "CandyCraft.common.ClientProxy")
	public static CommonProxy proxy;
	

	
	
	public static CreativeTabs CandyTab = new CreativeTabs("CandyTab"){
        public ItemStack getIconItemStack() {
                return new ItemStack(blockCottonSapling,1,0);
        }
};
	
	@PreInit
	public void preInit(FMLPreInitializationEvent event) {
		
		
		
		log = event.getModLog();
	    Configuration config;
	    try
	    {
	      File configFile = new File(new File(mc.getMinecraftDir(), "config"), "CandyCraft.cfg");

	      config = new Configuration(configFile);
	      config.load();

	      log.info(new StringBuilder().append("Config loaded from ").append(configFile.getAbsolutePath()).toString());
	    } catch (Exception e) {
	      log.warning(new StringBuilder().append("Error while trying to access configuration! ").append(e).toString());
	      config = null;
	    }


	    if (config != null) {
	    	
	    	paperBlockId = config.get(Configuration.CATEGORY_BLOCK, "Paper Block", 175).getInt();
	    	chocolateDirtId = config.get(Configuration.CATEGORY_BLOCK, "Chocolate Dirt", 176).getInt();
	    	chocolateGrassId = config.get(Configuration.CATEGORY_BLOCK, "Chocolate Grass", 177).getInt();
	    	cottonCandyLeavesId = config.get(Configuration.CATEGORY_BLOCK, "Cotton Candy Leaves", 178).getInt();
	    	cottonCandySaplingId = config.get(Configuration.CATEGORY_BLOCK, "Cotton Candy Sapling", 179).getInt();
	    	taffyLogId = config.get(Configuration.CATEGORY_BLOCK, "Taffy Log", 180).getInt();

	    	
	    	
	    	
	    }
		try{
			config.save();
		}catch(Exception e){
			log.warning(new StringBuilder().append("Error while trying to save configuration! ").append(e).toString());
		}
		
		
	}
	
	
	public static Block blockPaperBlock = new BlockPaperBlock(paperBlockId, Material.leaves).setUnlocalizedName("PaperBlock");
	public static Block blockCandyDirt = new Block(chocolateDirtId, Material.ground).setUnlocalizedName("CandyCraft:chocoDirt");
	public static Block blockCottonCandyField = new BlockCandyGrass(chocolateGrassId).setUnlocalizedName("chocoDirtSide");
	public static Block blockCottonLeaves = new BlockCottonLeaves(cottonCandyLeavesId).setUnlocalizedName("Leaf");
	public static Block blockCottonSapling = new BlockCottonSapling(cottonCandySaplingId, 0).setUnlocalizedName("Sapling");
	public static Block blockTaffyLog = new BlockCandyLog(taffyLogId).setUnlocalizedName("TaffyLog");


	
	
	@Init
	public void init(FMLInitializationEvent event) {
		GameRegistry.registerBlock(blockCottonCandyField, "blockCandyField");
		GameRegistry.registerBlock(blockPaperBlock, "blockPaper");
		GameRegistry.registerBlock(blockCandyDirt, "candyDirt");
		MinecraftForge.EVENT_BUS.register(new GenEventClass());
		proxy.registerRenderInformation();
		EntityRegistry.registerModEntity(EntityCandyGiraffe.class, "CandyGiraffe", 2, this, 80, 3, true);
        EntityRegistry.addSpawn(EntityCandyGiraffe.class, 5, 2, 6, EnumCreatureType.creature, this.biome, BiomeGenBase.plains);
        LanguageRegistry.instance().addStringLocalization("entity.instance.yourMob.name", "Your Mob");
        ModLoader.registerEntityID(EntityCandyGiraffe.class, "MyEntityName", 2000, Color.BLUE.getRGB(), Color.pink.getRGB());
		
		
		
		LanguageRegistry.addName(blockCottonCandyField, "Candy Grass");
		LanguageRegistry.addName(blockCandyDirt, "Candy Dirt");
		LanguageRegistry.addName(blockPaperBlock, "Block of Paper");
		GameRegistry.addBiome(new BiomeGenRapists_Paradise(50));
		
	}

	@PostInit
	public static void postInit(FMLPostInitializationEvent event) {
		
	}
}